/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tickets;

import java.sql.ResultSet;

/**
 *
 * @author Jah
 */
public class Auxiliar {

    public static String creaTabla(String[] header, ResultSet rs, boolean radioButton) {
        StringBuilder sb = new StringBuilder();
        int indexID = 0;
//        if (radioButton) {
//            String[] nvoHeader = new String[header.length + 1];
//            System.arraycopy(header, 0, nvoHeader, 0, header.length);
//            nvoHeader[nvoHeader.length - 1] = "Seleccionar";
//            header = nvoHeader;
//
//            for (int i = 0; i < header.length; i++) {
//                if (header[i].compareToIgnoreCase("ID") == 0) {
//                    indexID = i + 1;
//                    break;
//                }
//            }
//
//        }

        sb.append("<table border=\"1\">");

        // Header
        sb.append("<tr>\n");
        for (int i = 0; i < header.length; i++) {
            sb.append("<th>");
            sb.append(header[i]);
            sb.append("</th>\n");
        }
        sb.append("</tr>\n");

        // Contenido
        try {
            int cuantasColumnas;
            if (radioButton) {
                cuantasColumnas = header.length + 1;
            } else {
                cuantasColumnas = header.length;
            }

            while (rs.next()) {
                sb.append("<tr>\n");
                for (int i = 1; i <= cuantasColumnas; i++) {
                    sb.append("<td>");
                    if (i == header.length + 1) {
                        sb.append("<input type=\"radio\" name=\"idTicket\" value=\"" + rs.getString(1) + "\">");
                        System.out.println("radio");
                    } else {
                        sb.append(rs.getString(i));
                        System.out.println(rs.getString(i));
                    }
                    sb.append("</td>\n");

                }
                sb.append("</tr>\n");
            }
        } catch (Exception e) {
        }
        sb.append("</table>");

        return sb.toString();
    }
    public static String creaSelect(Object values[],String name){
        StringBuffer sb = new StringBuffer();
        sb.append("<select name=\""+name+"\">");
        for (int i = 0; i<values.length;i++){
            sb.append("<option value=\""+i+"\">"+values[i]+"</option>");
        }
        sb.append("</select>");
        
        
        return sb.toString();
        
    }

    public static void main(String[] args) {
        Controlador c = new Controlador();
        ResultSet prueba = c.conexion.ejecutaSP("TICKETS_POR_CLIENTE()");
        String header[] = {"Ticket ID", "Fecha de creación",
            "Nombre del cliente", "Tipo de Ticket", "Estado del Ticket"};
        System.out.println(creaTabla(header, prueba, true));
        //System.out.println(creaSelect(TipoTicket.values()));
    }
}
